#include "allhead.h"
#include "Graf.h"

int SurfBorderSearch_graf(GRAF graf, LPGRAF graf1)
{
 int i,b=0,ret;

 if(graf.n==0)
	 return 1;

 copy_graf(graf, graf1);

 for(i=0;i<graf1->nt;i++)
  if(is_zero_angle_inside_trg(*graf1,i))
		{
		b=1;
		printf("trg %d has zerro angle\n",i);
//		return 1;
		}

 for(i=0;i< graf1->n;i++)
	{
     if(DebugPrint)
	 if(i%100==0)fprintf(stderr,"\rreduce_vertex %8d%%",i*100/graf1->n);

	if(graf1->vertex[i].gr==IsInterior)
	  if(graf1->vertex[i].ntrg<=2)
		{
		printf("vert %d ntrg=%d<3\n",i,graf1->vertex[i].ntrg);
		return 2;
		}
	  else
		if(ret=reduce_vertex(graf1,i))
			{
			printf("Error %d in reduce_vertex %d \n",ret,i);
			return 4;
			}
	}

 if(DebugPrint) { fprintf(stderr,"\rreduce_vertex %8d%%",100); printf("\n"); }

 return 0;
}

int SurfRemoveAlones(LPGRAF graf)
{
 int i;

 for(i=0;i<graf->n;i++)
	 if(graf->vertex[i].ntrg==0)
		 DelAloneVertex(graf,i--);

 return 0;
}


